package com.tencent.wxcloudrun.service.impl;

import com.tencent.wxcloudrun.dao.KTaskMapper;
import com.tencent.wxcloudrun.model.KTask;
import com.tencent.wxcloudrun.service.TaskService;
import com.tencent.wxcloudrun.utils.SnowFlakeUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Random;

/**
 * @Author yuyongkang
 * @Date 2025/9/16 16:18
 */
@Service
public class TaskServiceImpl implements TaskService {

    //机器码
    public static final Long MACHINE_ID = Long.valueOf(new Random().nextInt(9) + 1);

    @Resource
    private KTaskMapper kTaskMapper;

    @Override
    public int insert(KTask task) {
        task.setId(SnowFlakeUtil.getInstance(MACHINE_ID).nextId());
        task.setCreateTime(new Date());
        return kTaskMapper.insertTask(task);
    }
}
